#pragma once
#ifndef _OBJECT_H
#define _OBJECT_H

#include "../common/Ptr.hpp"

#include "Terrain.h"
#include "ObjectProperty.h"
#include "Player.h"


class Object
{
private:
  Ptr< ObjectProperty > _porperty;

  Player _owner;
  UINT _type;

  // Position & Rotation
  Position3f _centerPos;
  Rotation3f _rotation;
  float _forwardAngle;

  // Target
  Position3f _targetPos;
  Ptr< Object > _fightTarget;

  // Status
  bool _selected;
  bool _underAttack;
  float _numberLeft;

  Ptr< Terrain > _pTerrian;

  void _fight ();
  void _attack (Ptr< Object > target);
  void _be_attacked_by (Ptr< Object > enemy);
  void _trace_target ();
  void _move ();

public:

  // x & y is the initial position
  Object (UINT type, Player owner,
          Ptr< ObjectProperty > pObjProperty,
          Ptr< Terrain > pTerrian,
          float x, float y,
          int number = 1, float forward = 0.0f);


  // Getter functions
  UINT type_id () const;
  Player owner () const;

  // Get position & rotation
  const Position3f& center () const;
  const Rotation3f& rotation () const;
  float forward_angle () const;

  // Get target
  const Position3f& target_pos () const;
  const Ptr< Object > fight_target () const;

  // Get status
  bool selected () const;
  bool under_attack () const;
  int number_left () const;
  bool exist () const;

  const Ptr< ObjectProperty > properties () const;

  // Control functions
  void set_target (float x, float y);
  void set_target (Object* target);
  void select ();
  void deselect ();
  bool update ();

};

#endif